<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>
			修改栋数
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="css/main.css" media="all">
		<script type="text/javascript" src="lib/loading/okLoading.js"></script>

		<script src="js/base.js"></script>
		<style>
			.imgs {
				display: none;
			}
		</style>

	</head>
	<body>
		<div class="x-body">
			<form class="layui-form layui-form-pane" action="" id="add">
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<input type="hidden" name="id" value="">
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>所属小区
								</label>
								<div class="layui-input-block">
									<select name="community_id" id="community_id">

									</select>
								</div>
								<script>
									let dongshuString = localStorage.getItem("dongshu_edit");
									let dongshu = JSON.parse(dongshuString);

									let url = "http://localhost:8080/wuye/XiaoQuController/selectXiaoQuAll";
									rest(url, "get", null, function(r) {
										let arr = r.data;
										let innerHTML = "";

										for (let i = 0; i < arr.length; i++) {
											if (dongshu.suoshuxiaoqu == arr[i].mingcheng) {
												innerHTML = innerHTML + " <option value=\"" + arr[i].mingcheng + "\" selected>" + arr[i]
													.mingcheng +
													"</option>";
											} else {
												innerHTML = innerHTML + " <option value=\"" + arr[i].mingcheng + "\" >" + arr[i]
													.mingcheng +
													"</option>";
											}

										}
										document.getElementById("community_id").innerHTML = innerHTML;
									});
								</script>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>栋数名称
								</label>
								<div class="layui-input-block">
									<input type="text" id="dongshumingcheng" name="buildings_name" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" required=""
										lay-verify="required" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>总户数
								</label>
								<div class="layui-input-block">
									<input type="text" id="zonghushu" name="households" autocomplete="off"
										placeholder="请输入数字" class="layui-input" required="number" lay-verify="number"
										value="">
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">
									<span class='x-red'>*</span>描述
								</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入内容" id="miaoshu" name="desc"
										class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<button class="layui-btn" type="button" lay-filter="add" lay-submit="">
									保存
								</button>
							</div>
							<div style="height:100px;"></div>
						</div>

					</div>

				</div>
			</form>
		</div>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/x-layui.js" charset="utf-8"></script>


		<script>
			document.getElementById("community_id").value = dongshu.suoshuxiaoqu;
			document.getElementById("dongshumingcheng").value = dongshu.dongshumingcheng;
			document.getElementById("zonghushu").value = dongshu.zonghushu;
			document.getElementById("miaoshu").value = dongshu.miaoshu;



			layui.use(['element', 'layer', 'form'], function() {
				$ = layui.jquery; //jquery
				lement = layui.element(); //面包导航
				layer = layui.layer; //弹出层
				form = layui.form();
				okLoading.close($);

				//监听提交
				form.on('submit(add)', function(data) {
					let suoshuxiaoqu = document.getElementById("community_id").value;
					let dongshumingcheng = document.getElementById("dongshumingcheng").value;
					let zonghushu = document.getElementById("zonghushu").value;
					let miaoshu = document.getElementById("miaoshu").value;
					let url = "http://localhost:8080/wuye/DongShuController/edit";
					let method = "post";
					let json = {};
					json.id = dongshu.id;
					json.suoshuxiaoqu = suoshuxiaoqu;
					json.dongshumingcheng = dongshumingcheng;
					json.zonghushu = zonghushu;
					json.miaoshu = miaoshu;

					rest(url, method, json, function(r) {
						if (r.code == 200) {
							//添加成功
							layer.msg("修改成功", {
								icon: 6,
								time: 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.msg("修改失败", {
								icon: 5,
								time: 2000
							});
							return false;
						}
					});
					return false;
				});

			})
		</script>

	</body>
</html>